package cn.com.dcsgo.service.impl;

import cn.com.dcsgo.mapper.AdminMapper;
import cn.com.dcsgo.model.acl.Admin;
import cn.com.dcsgo.service.AdminService;
import cn.com.dcsgo.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * AdminServiceImpl
 *
 * @author Dcsgo
 * @since 2025/3/18 17:07
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Override
    public IPage<Admin> selectAdminPage(Page<Admin> pageParam, AdminQueryVo adminQueryVo) {
        String username = adminQueryVo.getUsername();
        String name = adminQueryVo.getName();
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        //不为空的属性作为查询条件
        if (!StringUtils.isEmpty(username)) {
            //username 使用等值判断
            wrapper.eq(Admin::getUsername, username);
        }
        if (!StringUtils.isEmpty(name)) {
            //name 使用模糊匹配
            wrapper.like(Admin::getName, name);
        }
        return baseMapper.selectPage(pageParam, wrapper);
    }
}
